import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from './main'
import TheaterRouter from './theater'
import walletsRouter from './wallet'
import CalendarRouter from './sFunc'
import maprRouter from './sFunc/map'
import CityRouter from './sFunc/city'
import ShowTimeRouter from './sFunc/showTime'
//thx
import showRouter from './film_thx/show' //thx
import openPluskRouter from './film_thx/openPlus' //thx
//ht
import TetailRouter from './detail_ht'
import CenterRouter from './center_ht'
import LoginRouter from './Login_ht'
import RegRouter from './reg_ht'
import store from '../store'

//zlm
// 导入路由模块 zlm
import PerDetails from './predetail_zlm'
import Kfrouter from "./predetail_zlm/kf"
Vue.use(VueRouter)

const routes = [
    Main,
    TheaterRouter,
    walletsRouter,
    CalendarRouter,
    maprRouter,
    CityRouter,
    showRouter,
    openPluskRouter,
    TetailRouter,
    CenterRouter,
    LoginRouter,
    RegRouter,
    PerDetails,
    Kfrouter,
    ShowTimeRouter,
    {
        path: '/',
        redirect: '/main'
    },
    {
        path: '*',
        component: () =>
            import ('@/views/Log_ht/errer_ht')
    }
]

const router = new VueRouter({
        mode: 'history',
        base: process.env.BASE_URL,
        routes
    })
    //ht
router.beforeEach((to, from, next) => {
    // 判断不是登录才验证
    if ('/login' !== to.path) { // 不是登录页面
        if (store.state.token) { // vuex中是否有
            next()
        } else {
            if (sessionStorage.getItem('token')) { // sessionStorage中要是没有，则进入登录页面
                store.dispatch('setToken', sessionStorage.getItem('token'))
                next()
                return
            }
                next()
        }
    } else { // 登录页面不验证
        next()
    }
})
export default router